const path = require("path");
const url = require("url");
const env = process.argv[2];
const { app, BrowserWindow } = require("electron");
const onIpcMain = require("./ipcMain");

// 创建一个窗口
module.exports = () => {
  const trayIcon = path.join(__dirname, "./assets/favicon.ico");
  const mainWindow = new BrowserWindow({
    title: "ll",
    width: 950,
    height: 650,
    minHeight: 500,
    minWidth: 700,
    webPreferences: {
      preload: path.join(__dirname, "./preload.js"),
    },
    frame: false,
    autoHideMenuBar: true,
    titleBarStyle: "hidden",
    useContentSize: true,
    icon: trayIcon,
    backgroundColor: "rgba(0, 0, 0, 0)",
    transparent: true,
  });

  if (process.platform === "darwin") {
    app.dock.setIcon(path.join(__dirname, "./assets/favicon.icns"));
  }

  if (env === "dev") {
    mainWindow.loadURL("http://localhost:3012/");
  } else {
    mainWindow.loadURL(
      url.format({
        pathname: path.join(__dirname, "../build/index.html"),
        protocol: "file:",
        slashes: true,
      })
    );
  }

  onIpcMain(mainWindow);

  return mainWindow;
};
